package com.examination.system.administrator.futurerTask;


import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

/**
 * @author 寇淇芮
 * @Date 2019/11/4 15:16
 */
public class JamesFutureTask<V> implements Runnable, Future<V> {

    Callable<V> callable;
    V result = null;
    public JamesFutureTask(Callable<V> callable){
        this.callable = callable;
    }
    @Override
    public void run() {
        try {
            result = callable.call();

            int i = 0;
            synchronized (this){
                this.notifyAll();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException {
        if(result!=null){return result;}
        //
        synchronized (this){
            this.wait(); //
        }
        return result;
    }

    @Override
    public boolean cancel(boolean mayInterruptIfRunning) {
        return false;
    }

    @Override
    public boolean isCancelled() {
        return false;
    }

    @Override
    public boolean isDone() {
        return false;
    }

    @Override
    public V get() throws InterruptedException, ExecutionException {
        return null;
    }


}
